package org.example.demo21.iterator.iter;

import org.example.demo21.iterator.DrinkIterator;
import org.example.demo21.iterator.entity.MenuItem;

import java.util.List;

/**
 *
 * @author guocong
 * @since 2024/4/1 13:50
 */
public class CoffeeIter implements DrinkIterator {

    List<MenuItem> menuItems;
    int position = 0;

    public CoffeeIter(List<MenuItem> menuItems) {
        this.menuItems = menuItems;
    }

    @Override
    public boolean hasNext() {
        return position <= menuItems.size() - 1 && menuItems.get(position) != null;
    }

    @Override
    public Object next() {
        MenuItem menuItem = menuItems.get(position);
        position++;
        return menuItem;
    }

}
